import java.util.concurrent.atomic.AtomicInteger;

public class Demo1 {
    //具有原子性的特性,内部实现没有用到锁,更加的高效
    public static AtomicInteger a = new AtomicInteger();

    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(()-> {
            for (int i = 0; i < 50000; i++) {
                a.getAndIncrement();
            }
        });

        Thread t1 = new Thread(()-> {
            for (int i = 0; i < 50000; i++) {
                a.getAndIncrement();
            }
        });

        t.start();
        t1.start();
        t.join();;
        t1.join();
        System.out.println(a);
    }
}
